//
//  MovieDetailViewController.m
//  newDouban
//
//  Created by dllo on 15/10/17.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "MovieDetailViewController.h"
#import "MovieDetailView.h"
#import "AllMovieDetailViewController.h"
#import "AppTools.h"
#import "Movie.h"
#import "MBProgressHUD.h"
@interface MovieDetailViewController ()<pushToAllMovieDetailViewDelegate>

@property (nonatomic, retain) NSMutableArray *movieArray;
@property (nonatomic, retain) MBProgressHUD *hub;

@end

@implementation MovieDetailViewController

- (void)dealloc
{
    [_hub release];
    [_movieArray release];
    [super dealloc];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    MovieDetailView *movieDTV = [[MovieDetailView alloc] initWithFrame:self.view.frame];
    movieDTV.pushDelegate = self;
    [self.view addSubview:movieDTV];
    [movieDTV release];
    
    
    
    self.movieArray = [NSMutableArray array];
    NSString *urlStr = @"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/movielist.php";
    
    
    self.hub = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [self.hub show:YES];
    self.hub.labelText = @"正在加载中....";
    
    [AppTools getDataWithURL:urlStr block:^(id result) {
        NSMutableDictionary *dic = result;
        NSString *reason = [dic objectForKey:@"reason"];
        NSMutableArray *array = [dic objectForKey:@"result"];
        if ([reason isEqualToString:@"success"]) {
            for (NSDictionary *dicTemp in array) {
                Movie *movie = [[Movie alloc] init];
                [movie setValuesForKeysWithDictionary:dicTemp];
                [self.movieArray addObject:movie];
                [movie release];
            }
            
            //[self.tableV reloadData];
            [self.hub hide:YES];
            
            [movieDTV setMovieArr:self.movieArray];
            
        } else {
            NSLog(@"请求失败");
        }
        
    }];
    
}


- (void)pushToAllMovieDetailViewTag:(NSString *)strTag
{
    AllMovieDetailViewController *allMovieDTVC = [[AllMovieDetailViewController alloc] init];
    allMovieDTVC.movieID = strTag;
    [self.navigationController pushViewController:allMovieDTVC animated:YES];
    [allMovieDTVC release];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
